package com.monitor.ui;

import javax.swing.border.AbstractBorder;
import java.awt.*;

/**
 * 自定义圆角边框组件
 * 用于创建具有圆角效果的边框
 */
public class RoundedBorder extends AbstractBorder {
    private static final long serialVersionUID = 1L;
    private Color color;
    private int radius;
    
    /**
     * 创建指定颜色和圆角半径的边框
     * 
     * @param color 边框颜色
     * @param radius 圆角半径
     */
    public RoundedBorder(Color color, int radius) {
        this.color = color;
        this.radius = radius;
    }
    
    @Override
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
        Graphics2D g2d = (Graphics2D) g.create();
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setColor(color);
        g2d.drawRoundRect(x, y, width - 1, height - 1, radius, radius);
        g2d.dispose();
    }
    
    @Override
    public Insets getBorderInsets(Component c) {
        return new Insets(this.radius + 1, this.radius + 1, this.radius + 2, this.radius);
    }
    
    @Override
    public Insets getBorderInsets(Component c, Insets insets) {
        insets.left = insets.top = insets.right = insets.bottom = this.radius + 1;
        return insets;
    }
    
    @Override
    public boolean isBorderOpaque() {
        return false;
    }
}